package com.atguigu.tingshu.user.strategy;

import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.user.strategy.impl.AlbumStrategy;
import com.atguigu.tingshu.user.strategy.impl.TrackStrategy;
import com.atguigu.tingshu.user.strategy.impl.VipStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class StrateFactory {
    @Autowired
   private Map<String,ItemTypeStrategy> stringItemTypeStrategyMap;


    /**
     * 将IOC容器中ItemTypeStrategy接口下所有实现类对象注入到Map中
     * Map中Key：Bean对象ID
     * Map中Value：实现类对象
     * {"1001":购买类型为专辑策略类对象}
     * {"1002":购买类型为声音策略类对象}
     * {"1003":购买类型为会员策略类对象}
     */
//根据购买项目类型获取具体策略实现类对象
    public ItemTypeStrategy getStrategy(String itemType){
        if(stringItemTypeStrategyMap.containsKey(itemType)){
            return stringItemTypeStrategyMap.get(itemType);
        }
        throw new GuiguException(500,"该策略"+itemType+"实现类不存在");
    }

}
